import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ObjectInputStreamDemo16 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        FileOutputStream stream = new FileOutputStream("F:\\IdeaProjects\\MyJava230203\\day27\\dir\\7.txt");
//        ObjectOutputStream objectOutputStream = new ObjectOutputStream(stream);
//        List<Person> personList = new ArrayList<>();
//        personList.add(new Person("张凯明", 20,"男"));
//        personList.add(new Person("邹杨", 20,"男"));
//        personList.add(new Person("王兵", 20,"男"));
//        objectOutputStream.writeObject(personList);
//        objectOutputStream.flush();
//        objectOutputStream.close();


        // 读出来
        FileInputStream fileInputStream = new FileInputStream("F:\\IdeaProjects\\MyJava230203\\day27\\dir\\7.txt");
        ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
        List<Person> personList1 = (List<Person>) objectInputStream.readObject();

        for (Person person : personList1) {
            System.out.println(person);
        }



    }
}


class Person implements Serializable {
//    private static final long serialVersionUID = 1L;// 唯一标识
    private String name;
    private int age;
    private String gender;
    private String country;

    public Person(String name, int age, String gender, String country) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.country = country;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                ", country='" + country + '\'' +
                '}';
    }
}